package com.marchsoft.service.impl;

import com.marchsoft.common.enums.ExceptionEnum;
import com.marchsoft.common.exception.CommonException;
import com.marchsoft.dao.GroupMapper;
import com.marchsoft.domain.AccountPass;
import com.marchsoft.domain.Group;
import com.marchsoft.service.IGroupService;
import com.marchsoft.vo.GroupExtra;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * class description：
 * author：rsw
 * Date: 2019/11/17
 * Time: 10:59
 **/
@Service
public class GroupServiceImpl implements IGroupService {

    @Resource
    private GroupMapper groupMapper;

    /**
     * 查询所有的兴趣小组的信息
     * @return 所有小组信息
     */
    @Override
    public List<GroupExtra> queryGroupAll() {
        if (CollectionUtils.isEmpty(groupMapper.queryGroupAll())){
            throw new CommonException(ExceptionEnum.GROUP_NOT_FOUND);
        }
        return groupMapper.queryGroupAll();
    }

    /**
     * 根据小组id查询其信息（包含老师信息）
     * @param gid 小组id
     * @return 一条小组信息
     */
    @Override
    public GroupExtra queryGroupByGid(Integer gid) {
        if (groupMapper.queryGroupByGid(gid)==null){
            throw new CommonException(ExceptionEnum.GROUP_NOT_FOUND);
        }
        return groupMapper.queryGroupByGid(gid);
    }


}

